package loveqq.niceexcel.read;

import loveqq.niceexcel.converter.Converter;
import loveqq.niceexcel.read.handler.ReadHandler;
import lombok.Getter;
import lombok.Setter;

import java.util.LinkedHashSet;
import java.util.List;

/**
 * Excel读取指定sheet
 *
 * @author zhongjh@tsintergy.com
 * @date 2022-08-22
 */
@Getter
@Setter
public class ReadSheet<T> {
    /**
     * 表头+返回数据类型
     */
    private final Class<T> headClass;
    /**
     * sheet索引
     */
    private LinkedHashSet<Integer> sheetIndexes;
    /**
     * sheet名字
     */
    private LinkedHashSet<String> sheetNames;
    /**
     * 全部sheet
     */
    private boolean allSheet;
    /**
     * 读取处理器
     */
    private List<ReadHandler> readHandlerList;
    /**
     * 单元格数据转换器
     */
    private List<Converter<?>> converterList;


    public ReadSheet(Class<T> headClass) {
        this.headClass = headClass;
    }

    public void setSheetIndexes(LinkedHashSet<Integer> sheetIndexes) {
        this.sheetIndexes = sheetIndexes;
        this.sheetNames = null;
        this.allSheet = false;
    }

    public void setSheetNames(LinkedHashSet<String> sheetNames) {
        this.sheetNames = sheetNames;
        this.sheetIndexes = null;
        this.allSheet = false;
    }

    public void setAllSheet(boolean allSheet) {
        this.allSheet = allSheet;
        this.sheetIndexes = null;
        this.sheetNames = null;
    }

    @Override
    public String toString() {
        String result = "ReadSheet{ ";
        if (allSheet) {
            result += "allSheet=true";
        } else if (sheetIndexes != null) {
            result += "sheetIndex=" + sheetIndexes;
        } else if (sheetNames != null) {
            result += "sheetName=" + sheetNames;
        }
        result += " }";
        return result;
    }
}
